home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1999 Spring / macformat-077.iso / Shareware Plus / Development / Akua Sweets 131 / Akua Sweets Examples / Imaging / Startup Progress Picture < prev   
Encoding:
Text File  |  1999-03-04  |  5.7 KB  |  291 lines  |  [TEXT/ToyS]

  1. property kasSysPicts : {-16506, -16505, -16504, -16503, -16502, -16501}
  2. property kasSysDepth : {0, 4 + 32, 1, 8, 4 + 32, 1} -- + 32 for greyscale, 0 for deepest current monitor
  3. property kasTitle : "Startup Progress Picture"
  4.  
  5. global gasStat
  6.  
  7.  
  8. on run
  9.     set gasStat to 0
  10.     
  11.     if (WeHavePreserves()) then
  12.         set choice to ShowChoice("Do you wish to view the current Startup Progress Pictures, copy the original to the clipboard, or restore their original state?", ¬
  13.             {"Copy", "Restore", "View"})
  14.         
  15.         if choice is "View" then
  16.             ShowEm()
  17.         else if choice is "Copy" then
  18.             CopyMain(true)
  19.         else
  20.             RestorePreserve()
  21.         end if
  22.     else
  23.         ShowStatus(1, "Drop an image file on this script to have it replace your MacOS Startup Progress Picture.")
  24.         
  25.         set choice to ShowChoice("Do you wish to view the current Startup Progress Pictures or copy the current picture to the clipboard?", ¬
  26.             {"Cancel", "Copy", "View"})
  27.         
  28.         if (choice is "View") then
  29.             ShowEm()
  30.         else if choice is "Copy" then
  31.             CopyMain(false)
  32.         end if
  33.     end if
  34.     
  35.     CloseStatus()
  36. end run
  37.  
  38.  
  39. on open fsObjs
  40.     set gasStat to 0
  41.     
  42.     if (the number of items of fsObjs is not 1) then
  43.         ShowAlert("You can only drop one picture on this script." & return & return & ¬
  44.             "Dropping more than one is only a waste of time...")
  45.     else
  46.         -- Save current for later restoration
  47.         if not WeHavePreserves() then ¬
  48.             PreserveCurrent()
  49.         
  50.         InstallEm(item 1 of fsObjs)
  51.     end if
  52.     
  53.     CloseStatus()
  54. end open
  55.  
  56.  
  57. on InstallEm(fsObj)
  58.     set fname to catalog name of (basic info for fsObj)
  59.     
  60.     ShowStatus(2, "Loading " & fname)
  61.     
  62.     set n to the number of items of kasSysPicts
  63.     set pic to the image from fsObj
  64.     
  65.     ShowStatus(2, "Installing " & fname)
  66.     
  67.     set havePres to WeHavePreserves()
  68.     
  69.     repeat with i from 1 to n
  70.         ShowStatus(3, "Drawing " & i & " of " & n)
  71.         
  72.         set rn to item i of kasSysPicts
  73.         set newDepth to item i of kasSysDepth
  74.         
  75.         -- Get deepest?
  76.         if (newDepth is 0) then set newDepth to GetDeepestDepth()
  77.         
  78.         set win to ShowOne(rn, havePres)
  79.         pause for 44 -- Allow window to update itself
  80.         
  81.         set wBox to {0, 0} & (window dimensions of win)
  82.         
  83.         -- Replace old picture with new one in window
  84.         draw a picture ¬
  85.             into win ¬
  86.             inside of wBox ¬
  87.             using data pic ¬
  88.             with a clear slate
  89.         
  90.         ShowStatus(3, "Capturing " & i & " of " & n)
  91.         
  92.         -- Capture it
  93.         set newPic to ¬
  94.             capture picture from win ¬
  95.                 using depth newDepth ¬
  96.                 with pixel conversion and dithering
  97.         
  98.         ShowStatus(3, "Showing " & i & " of " & n)
  99.         
  100.         draw a picture ¬
  101.             into win ¬
  102.             inside of wBox ¬
  103.             using data newPic ¬
  104.             with a clear slate without recording
  105.         
  106.         ShowStatus(3, "Saving " & i & " of " & n)
  107.         
  108.         save resource newPic ¬
  109.             named ("Akua") ¬
  110.             numbered rn
  111.         
  112.         ShowStatus(3, "Done " & i & " of " & n)
  113.         
  114.         CloseShow(win)
  115.     end repeat
  116. end InstallEm
  117.  
  118.  
  119. on CopyMain(fromPreserve)
  120.     if (fromPreserve) then
  121.         clip RestoreGet(item 1 of kasSysPicts)
  122.         PasteInScrapBook()
  123.     end if
  124.     
  125.     set win to ShowOne(item 1 of kasSysPicts, false)
  126.     clip (capture picture from win)
  127.     CloseShow(win)
  128.     
  129.     PasteInScrapBook()
  130. end CopyMain
  131.  
  132.  
  133. on PasteInScrapBook()
  134.     tell application "Scrapbook"
  135.         activate
  136.         input state {keys down:"V", command key down:true} -- paste it
  137.     end tell
  138.     activate
  139. end PasteInScrapBook
  140.  
  141.  
  142. on ShowEm()
  143.     repeat with rn in kasSysPicts
  144.         set win to ShowOne(rn, false)
  145.         
  146.         pause for 3 with seconds timing
  147.         
  148.         CloseShow(win)
  149.     end repeat
  150. end ShowEm
  151.  
  152.  
  153. on ShowOne(rn, fromPreserves)
  154.     if (fromPreserves) then
  155.         set spic to RestoreGet(rn)
  156.     else
  157.         set spic to the resource of type ¬
  158.             "PICT" numbered rn
  159.     end if
  160.     
  161.     return ¬
  162.         display drawing titled ("System Picture " & rn) ¬
  163.             starting with spic
  164. end ShowOne
  165.  
  166.  
  167. on CloseShow(win)
  168.     display drawing win ¬
  169.         with disposal
  170. end CloseShow
  171.  
  172.  
  173. on PreserveCurrent()
  174.     repeat with rn in kasSysPicts
  175.         ShowStatus(4, "Preserving " & rn)
  176.         PreserveOne(rn)
  177.     end repeat
  178.     
  179.     ShowStatus(4, "…")
  180. end PreserveCurrent
  181.  
  182.  
  183. on RestorePreserve()
  184.     repeat with rn in kasSysPicts
  185.         ShowStatus(4, "Restoring " & rn)
  186.         RestoreOne(rn)
  187.     end repeat
  188.     
  189.     ShowStatus(4, "…")
  190. end RestorePreserve
  191.  
  192.  
  193. property kpfNameOne : "System Picture "
  194. property kpfName : "Startup Progress Preserve"
  195.  
  196. on PreserveOne(rn)
  197.     set spic to the resource of type ¬
  198.         "PICT" numbered rn
  199.     
  200.     save preference spic ¬
  201.         named (kpfNameOne & rn) ¬
  202.         in file named kpfName
  203. end PreserveOne
  204.  
  205.  
  206. on RestoreOne(rn)
  207.     try
  208.         set spic to RestoreGet(rn)
  209.     on error
  210.         ShowAbort("There is apparently no preserve to restore!")
  211.     end try
  212.     
  213.     save resource spic ¬
  214.         numbered rn
  215. end RestoreOne
  216.  
  217.  
  218. on RestoreGet(rn)
  219.     return load preference named (kpfNameOne & rn) ¬
  220.         in file named kpfName
  221. end RestoreGet
  222.  
  223.  
  224. on WeHavePreserves()
  225.     set rn to the last item of kasSysPicts
  226.     
  227.     try
  228.         load preference named (kpfNameOne & rn) ¬
  229.             in file named kpfName
  230.     on error
  231.         return false
  232.     end try
  233.     
  234.     return true
  235. end WeHavePreserves
  236.  
  237.  
  238. on ShowAbort(msg)
  239.     return ShowChoice(msg, {"Cancel"})
  240. end ShowAbort
  241.  
  242.  
  243. on ShowAlert(msg)
  244.     return ShowChoice(msg, {"OK"})
  245. end ShowAlert
  246.  
  247.  
  248. on ShowChoice(msg, btns)
  249.     return button returned of ¬
  250.         (display dialog msg ¬
  251.             buttons btns ¬
  252.             default button (number of items of btns))
  253. end ShowChoice
  254.  
  255.  
  256. on ShowStatus(n, msg)
  257.     if (gasStat is 0) then
  258.         set gasStat to ¬
  259.             display info titled kasTitle ¬
  260.                 message "…" located at {20, 48}
  261.         display info gasStat message "…" at line 2
  262.         display info gasStat message "…" at line 3
  263.         display info gasStat message "…" at line 4
  264.     end if
  265.     
  266.     display info gasStat ¬
  267.         message msg ¬
  268.         at line n
  269. end ShowStatus
  270.  
  271.  
  272. on CloseStatus()
  273.     if (gasStat is not 0) then
  274.         display info gasStat with disposal
  275.         set gasStat to 0
  276.     end if
  277. end CloseStatus
  278.  
  279.  
  280. on GetDeepestDepth()
  281.     set disps to the display information
  282.     set deepest to 0
  283.     
  284.     repeat with disp in disps
  285.         set thisDepth to the monitor depth of disp
  286.         if (thisDepth > deepest) then set deepest to thisDepth
  287.     end repeat
  288.     
  289.     return deepest
  290. end GetDeepestDepth
  291.